<?php


abstract class BaseLapso extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $cp_lapso;


	
	protected $cf_decanato;


	
	protected $descripcion;


	
	protected $fecha_inicio;


	
	protected $fecha_final;


	
	protected $estatus;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getCpLapso()
	{

		return $this->cp_lapso;
	}

	
	public function getCfDecanato()
	{

		return $this->cf_decanato;
	}

	
	public function getDescripcion()
	{

		return $this->descripcion;
	}

	
	public function getFechaInicio($format = 'Y-m-d')
	{

		if ($this->fecha_inicio === null || $this->fecha_inicio === '') {
			return null;
		} elseif (!is_int($this->fecha_inicio)) {
						$ts = strtotime($this->fecha_inicio);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_inicio] as date/time value: " . var_export($this->fecha_inicio, true));
			}
		} else {
			$ts = $this->fecha_inicio;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getFechaFinal($format = 'Y-m-d')
	{

		if ($this->fecha_final === null || $this->fecha_final === '') {
			return null;
		} elseif (!is_int($this->fecha_final)) {
						$ts = strtotime($this->fecha_final);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_final] as date/time value: " . var_export($this->fecha_final, true));
			}
		} else {
			$ts = $this->fecha_final;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getEstatus()
	{

		return $this->estatus;
	}

	
	public function setCpLapso($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cp_lapso !== $v) {
			$this->cp_lapso = $v;
			$this->modifiedColumns[] = LapsoPeer::CP_LAPSO;
		}

	} 
	
	public function setCfDecanato($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_decanato !== $v) {
			$this->cf_decanato = $v;
			$this->modifiedColumns[] = LapsoPeer::CF_DECANATO;
		}

	} 
	
	public function setDescripcion($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->descripcion !== $v) {
			$this->descripcion = $v;
			$this->modifiedColumns[] = LapsoPeer::DESCRIPCION;
		}

	} 
	
	public function setFechaInicio($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_inicio] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_inicio !== $ts) {
			$this->fecha_inicio = $ts;
			$this->modifiedColumns[] = LapsoPeer::FECHA_INICIO;
		}

	} 
	
	public function setFechaFinal($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_final] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_final !== $ts) {
			$this->fecha_final = $ts;
			$this->modifiedColumns[] = LapsoPeer::FECHA_FINAL;
		}

	} 
	
	public function setEstatus($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->estatus !== $v) {
			$this->estatus = $v;
			$this->modifiedColumns[] = LapsoPeer::ESTATUS;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->cp_lapso = $rs->getString($startcol + 0);

			$this->cf_decanato = $rs->getString($startcol + 1);

			$this->descripcion = $rs->getString($startcol + 2);

			$this->fecha_inicio = $rs->getDate($startcol + 3, null);

			$this->fecha_final = $rs->getDate($startcol + 4, null);

			$this->estatus = $rs->getString($startcol + 5);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 6; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Lapso object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(LapsoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			LapsoPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(LapsoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = LapsoPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setCpLapso($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += LapsoPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = LapsoPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = LapsoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getCpLapso();
				break;
			case 1:
				return $this->getCfDecanato();
				break;
			case 2:
				return $this->getDescripcion();
				break;
			case 3:
				return $this->getFechaInicio();
				break;
			case 4:
				return $this->getFechaFinal();
				break;
			case 5:
				return $this->getEstatus();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = LapsoPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getCpLapso(),
			$keys[1] => $this->getCfDecanato(),
			$keys[2] => $this->getDescripcion(),
			$keys[3] => $this->getFechaInicio(),
			$keys[4] => $this->getFechaFinal(),
			$keys[5] => $this->getEstatus(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = LapsoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setCpLapso($value);
				break;
			case 1:
				$this->setCfDecanato($value);
				break;
			case 2:
				$this->setDescripcion($value);
				break;
			case 3:
				$this->setFechaInicio($value);
				break;
			case 4:
				$this->setFechaFinal($value);
				break;
			case 5:
				$this->setEstatus($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = LapsoPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setCpLapso($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCfDecanato($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setDescripcion($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setFechaInicio($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setFechaFinal($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setEstatus($arr[$keys[5]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(LapsoPeer::DATABASE_NAME);

		if ($this->isColumnModified(LapsoPeer::CP_LAPSO)) $criteria->add(LapsoPeer::CP_LAPSO, $this->cp_lapso);
		if ($this->isColumnModified(LapsoPeer::CF_DECANATO)) $criteria->add(LapsoPeer::CF_DECANATO, $this->cf_decanato);
		if ($this->isColumnModified(LapsoPeer::DESCRIPCION)) $criteria->add(LapsoPeer::DESCRIPCION, $this->descripcion);
		if ($this->isColumnModified(LapsoPeer::FECHA_INICIO)) $criteria->add(LapsoPeer::FECHA_INICIO, $this->fecha_inicio);
		if ($this->isColumnModified(LapsoPeer::FECHA_FINAL)) $criteria->add(LapsoPeer::FECHA_FINAL, $this->fecha_final);
		if ($this->isColumnModified(LapsoPeer::ESTATUS)) $criteria->add(LapsoPeer::ESTATUS, $this->estatus);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(LapsoPeer::DATABASE_NAME);

		$criteria->add(LapsoPeer::CP_LAPSO, $this->cp_lapso);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getCpLapso();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setCpLapso($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setCfDecanato($this->cf_decanato);

		$copyObj->setDescripcion($this->descripcion);

		$copyObj->setFechaInicio($this->fecha_inicio);

		$copyObj->setFechaFinal($this->fecha_final);

		$copyObj->setEstatus($this->estatus);


		$copyObj->setNew(true);

		$copyObj->setCpLapso(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new LapsoPeer();
		}
		return self::$peer;
	}

} 